home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / PBLIB1 / UNITS / PBTSTLIB.PAS < prev    next >
Pascal/Delphi Source File  |  1994-05-03  |  6KB  |  223 lines

  1. {SECTION ..PbTSTLIB }
  2. UNIT PbTSTLIB;
  3.  
  4. {
  5. Description : Some Procedures for monitoring HEAP & TIME use.
  6.  
  7. Author      : Howard Richoux
  8. Date        : 1/8/94  STARTING OVER
  9. Last revised:
  10. Application : IBM PC and compatibles, done in Turbo Pascal 5.5
  11. Status      : Placed in the Public Domain by HNR Software 1/29/1994
  12. Published in: none
  13. }
  14.  
  15. INTERFACE
  16.  
  17. uses PbMISC;
  18.  
  19. Procedure PbTSTLIBInit;
  20.                    {[TESTING] Initializes HEAP & TIME vars }
  21.  
  22. Procedure ShowMEM(s : string);
  23.                    {[TESTING] Displays Heap Use }
  24.  
  25. Procedure SetMEMCurrent;
  26.                    {[TESTING] Defines a new starting point }
  27.  
  28. Procedure TrackMEM;
  29.                    {[TESTING] Records current conditions, for max }
  30.  
  31. Function  MEMCurrentStr(str : string) : string;
  32.                    {[TESTING] returns string of ShowMEMCurrent }
  33.  
  34. Function  MEMChangeStr(str : string) : string;
  35.                    {[TESTING] returns string of ShowMEMChange }
  36.  
  37. Procedure ShowMEMCurrent(str : string);
  38.                    {[TESTING] Writeln of Heap Use since SetMEMCurrent }
  39.  
  40. Procedure ShowMEMChange(s : string);
  41.                    {[TESTING] Writeln of Heap Use since SetMEMCurrent IF CHANGED}
  42.  
  43.  
  44. var initmemavail  : longint;  {initial heap memory available to program }
  45. var initmaxavail  : longint;  {initial maximum chunk size available     }
  46. var memused       : longint;  {initmemavail - memavail  total used at present}
  47. var holdmemavail  : longint;  {some later point in time }
  48. var holdmemused   : longint;  {used since hold was reset }
  49. var prevmemused   : longint;  {previous printed memused }
  50. var holdmaxused   : longint;  {highest use since hold was reset}
  51. var netchange     : longint;  {tracking }
  52.  
  53.  
  54. Procedure SetTIMECurrent;
  55.                    {[TESTING] Starts Time tracking }
  56.  
  57. Function  TIMECurrentStr(str : string) : string;
  58.                    {[TESTING] Displays TICKS Use since SetTIMECurrent }
  59.  
  60. Procedure ShowTIMECurrent(str : string);
  61.                    {[TESTING] Displays TIME Use }
  62.  
  63.  
  64.  
  65.  
  66. var initticks     : longint;  {program start time ticks since midnight}
  67. var holdticks     : longint;  {some later point in time}
  68. var netticks      : longint;  {tracking}
  69. var totalticks    : longint;  {since start of program}
  70.  
  71. {SECTION .zImplementation }
  72. IMPLEMENTATION
  73.  
  74.  
  75. {SECTION  TrackTIME }
  76. Procedure TrackTIME;
  77.      begin
  78.      netticks   := TicksSinceMidnight - holdticks;
  79.      totalticks := TicksSinceMidnight - initticks;
  80.      end;
  81.  
  82.  
  83. {SECTION  SetTIMECurrent }
  84. Procedure SetTIMECurrent;
  85.      begin
  86.      holdticks := TicksSinceMidnight;
  87.      netticks  := 0;
  88.      end;
  89.  
  90.  
  91. {SECTION  TIMECurrentStr }
  92. Function  TIMECurrentStr(str : string) : string;
  93.                    {[TESTING] Displays TICKS Use since SetTIMECurrent }
  94. var s : string;
  95.      begin
  96.      TrackTIME;
  97.      TIMECurrentStr := leftstr(str,25)+
  98.                           ' time:'+longintstr(netticks,7)+
  99.                           '    total:'+longintstr(totalticks,7)+
  100.                           '   '+TicksToSecsStr(TicksSinceMidnight);
  101.      end;
  102.  
  103.  
  104. {SECTION  ShowTIMECurrent }
  105. Procedure ShowTIMECurrent(str : string);
  106.                    {[TESTING] Displays TIME Use }
  107.      begin
  108.      TrackTIME;
  109.      writeln(TimeCurrentStr(str));
  110.      end;
  111.  
  112.  
  113.  
  114.  
  115. {SECTION  TrackMEM }
  116. Procedure TrackMEM;
  117.      begin
  118.      holdmemused := (holdmemavail - memavail);      {could be negative}
  119.      if holdmemused > holdmaxused then holdmaxused := holdmemused;
  120.      netchange := holdmemused - prevmemused;
  121.      end;
  122.  
  123.  
  124. {SECTION  SetMEMCurrent }
  125. Procedure SetMEMCurrent;
  126.      begin
  127.      holdmemavail := MemAvail;
  128.      holdmemused  := 0;
  129.      prevmemused  := 0;
  130.      holdmaxused  := 0;
  131.      end;
  132.  
  133.  
  134. {SECTION  MEMCurrentStr }
  135. Function  MEMCurrentStr(str : string) : string;
  136.                    {[TESTING] Displays Heap Use since SetMEMCurrent }
  137. var s : string;
  138.      begin
  139.      TrackMem;
  140.      MEMCurrentStr := leftstr(str,25)+
  141.                           ' used:'+longintstr(holdmemused,7)+
  142.                           '   change:'+longintstr(netchange,7)+
  143.                           '   maxused:'+longintstr(holdmaxused,7);
  144.      prevmemused := holdmemused;
  145.      end;
  146.  
  147.  
  148. {SECTION  ShowMEMCurrent }
  149. Procedure ShowMEMCurrent(str : string);
  150.                    {[TESTING] Displays Heap Use since SetMEMCurrent }
  151.      begin
  152.      TrackMem;
  153.      writeln(MemCurrentStr(str));
  154.      end;
  155.  
  156.  
  157. {SECTION  MEMChangeStr }
  158. Function  MEMChangeStr(str : string) : string;
  159.                    {[TESTING] Displays Heap Use since SetMEMCurrent }
  160. var s : string;
  161.      begin
  162.      s := '';
  163.      TrackMem;
  164.      if netchange <> 0 then s := MEMCurrentStr(str);
  165.      MEMChangeStr := s;
  166.      end;
  167.  
  168.  
  169. {SECTION  ShowMEMChange }
  170. Procedure ShowMEMChange(s : string);
  171.                    {[TESTING] Displays Heap Use since SetMEMCurrent IF CHANGED}
  172.      begin
  173.      TrackMem;
  174.      if netchange <> 0 then ShowMEMCurrent(s);
  175.      end;
  176.  
  177.  
  178.  
  179. {SECTION  ShowMEM }
  180. Procedure ShowMEM(s : string);
  181.                    {[TESTING] Displays Heap Use }
  182. var netchange : longint;
  183.      begin
  184.      TrackMem;
  185.      memused := initmemavail-memavail;
  186.      writeln(leftstr(s,25),' used:',memused:7,'    Avail:',memavail:7,
  187.                            '  MaxAvail:',maxAvail:7);
  188.      prevmemused := holdmemused;
  189.      end;
  190.  
  191.  
  192.  
  193. {SECTION  SetMEMInitial }
  194. Procedure SetMEMInitial;
  195.      begin
  196.      initmemavail := memavail;
  197.      initmaxavail := maxavail;
  198.      SetMEMCurrent;
  199.      end;
  200.  
  201.  
  202. {SECTION  SetTIMEInitial }
  203. Procedure SetTIMEInitial;
  204.      begin
  205.      initticks := TicksSinceMidnight;
  206.      totalticks  := 0;
  207.      SetTIMECurrent;
  208.      end;
  209.  
  210.  
  211. {SECTION  PbTSTLIBInit }
  212. Procedure PbTSTLIBInit;
  213.      begin
  214.      SetMEMInitial;
  215.      SetTIMEInitial;
  216.      end;
  217.  
  218.  
  219. {SECTION  zzInitialization }
  220.      begin {initialization}
  221.      PbTSTLIBInit;
  222.      end.
  223.